package cn.edu.lingnan.controller;


import cn.edu.lingnan.service.DepartmentService;
import cn.edu.lingnan.entity.pojo.Result;
import cn.edu.lingnan.entity.vo.DepartmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/department-service")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/hierarchy")
    public Result<List<DepartmentVO>> getHierarchy() {
        return Result.success(departmentService.getHierarchy());
    }

    @PostMapping("/add")
    public Result addDepartment(@RequestBody DepartmentVO departmentVO) {
        departmentService.addDepartment(departmentVO);
        return  Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteDepartment(@PathVariable Integer id) {
        departmentService.deleteDepartmentById(id);
        return Result.success();
    }
}
